using System;
using System.Drawing;
using System.Collections.Generic;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using System.Linq;

namespace QLTV.Reports
{
    public partial class rptOnBoard : DevExpress.XtraReports.UI.XtraReport
    {
        public rptOnBoard()
        {
            InitializeComponent();
            total.BeforePrint += xrSubreport1_BeforePrint;
        }


        private void rptOnBoard_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

        }
        public void loadData(bool part1, bool part2, bool part3, bool part4)
        {
            tadOnBoarList.Fill(dsReport1.tblOnBoarList);
            Array listID = (from d in dsReport1.tblOnBoarList.AsEnumerable()
                            orderby d.nVesselId ascending
                            select d.nVesselId).Distinct().ToArray();

            int middle1 = listID.Length / 2;
            int middle2 = (listID.Length - (middle1 + 1)) / 2;
            int middle3 = middle1 + (listID.Length - (middle1 + 1)) / 2;

            int middle1Value = (int)listID.GetValue(middle1);
            int middle2Value = (int)listID.GetValue(middle2);
            int middle3Value = (int)listID.GetValue(middle3);

            if (part1)
                tadOnBoarList.FillByLessOrEqual(dsReport1.tblOnBoarList, middle2Value);
            if(part2)
                tadOnBoarList.FillByMiddle(dsReport1.tblOnBoarList, middle2Value, middle1Value);
            if (part3)
                tadOnBoarList.FillByMiddle(dsReport1.tblOnBoarList, middle1Value, middle3Value);
            if (part4)
                tadOnBoarList.FillByGreater(dsReport1.tblOnBoarList, middle3Value);


        }

        private void xrSubreport1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {

            ((rptCrewTypeTotal)((XRSubreport)sender).ReportSource).vesselID.Value = Convert.ToInt32(GetCurrentColumnValue("nVesselId"));
        }

    }
}
